package com.hotec.PROJECT_NAME.modules.sys.entity;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.hutool.core.util.StrUtil;
import com.gemcap.framework.data.annotation.Join;
import com.hotec.PROJECT_NAME.component.basic.BaseEntity;
import com.hotec.PROJECT_NAME.component.basic.LockAble;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Size;
import java.util.Date;
import java.util.List;


/**
 * 登录信息表
 *
 * @author llb
 */
@Data
@Table(name = "sys_account")
@Accessors(chain = true)
public class SysAccount extends BaseEntity implements LockAble {


//    //WX
//    @Column(name = "source")
//    private String source;

//    @Column(name = "org_id")
//    private String orgId;

    @Column(name = "shop_id")
    private String shopId;

    @Size(max = 60)
    @Column(name = "username")
    private String username;

//    @Column(name = "code")
    @Transient
    private String code;
    /**
     * 用户昵称
     */
    @Size(max = 100)
    @Column(name = "nickname")
    @Excel(name = "姓名")
    private String nickname;

    /**
     * 用户身份证
     */
    @Size(max = 100)
    @Column(name = "id_card")
    private String idCard;

    /**
     * 用户性别
     */
    @Size(max = 100)
    @Column(name = "sex")
    private String sex;

    /**
     * 用户头像地址
     */
    @Size(max = 200)
    @Column(name = "head_img")
    private String headImg;

    @Size(max = 100)
    @Column(name = "password")
    private String password;

    /**
     * 电话
     */
    @Size(max = 20)
    @Column(name = "mobile")
    @Excel(name = "电话")
    private String mobile;

    @Size(max = 100)
    @Column(name = "email")
    private String email;

    /**
     * 微信id
     */
    @Column(name = "open_id")
    private String openId;


    /**
     * 最后登录时间
     */
    @Column(name = "last_login_time")
    private Date lastLoginTime;

    /**
     * 限制登录时间
     */
    @Column(name = "limit_time")
    private Date limitTime;


//    @Column(name = "legal_num")
//    @Excel(name = "执照号码")
//    private String legalNum;


    @Column(name = "remark")
    private String remark;


    /**
     * 通讯地址
     */
    @Column(name = "address")
    private String address;

    /**
     * 是否实名认证 1是 0否
     */
    @Column(name = "has_real")
    private String hasReal;

    /**
     * 真实姓名
     */
    @Column(name = "real_name")
    private String realName;

    /**
     * 银行卡号
     */
    @Column(name = "bank_account")
    private String bankAccount;

    /**
     * 所属银行名称
     */
    @Column(name = "bank_name")
    private String bankName;

    /**
     * 所属银行编码
     */
    @Column(name = "bank_code")
    private String bankCode;

    /**
     * 所属系统
     */
    @Column(name = "system")
    private String system;

    /**
     * 该用户的角色列表
     */
    @Transient
    List<SysRole> roleList;


    /**
     * 用户的资源列表
     */
    @Transient
    List<SysResource> resources;

    /**
     * 旧密码
     */
    @Transient
    private String oldPassword;

    @Transient
    private String wxCode;

    @Transient
    private String token;

    @Transient
    private String session_key;

    @Transient
    private String errorMessage;
    @Transient
    private String shopName;
    @Transient
    private String shopAddress;
    @Transient
    private String displayName;

    @Transient
    @Join(reversefk = "account_id")
    List<SysRoleAccount> roleAccounts;

    public String getDisplayName (){
        String blankToDefault = StrUtil.blankToDefault(this.getRealName(), this.getNickname());

        return StrUtil.blankToDefault(blankToDefault, this.getUsername());
    }


    @Override
    public String getLockKey(String prefix) {
        return prefix+":"+this.getId();
    }
}
